package com.woniuxy.service.impl;

import com.woniuxy.entity.Grade;
import com.woniuxy.entity.Phase;
import com.woniuxy.mapper.PhaseMapper;
import com.woniuxy.service.GradeService;
import com.woniuxy.service.PhaseService;
import com.woniuxy.service.SubjectService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Arrays;
import java.util.List;


@Service
public class PhaseServiceImpl implements PhaseService {
    @Autowired
    private PhaseMapper phaseMapper;
    @Autowired
    private GradeService gradeService;

    @Autowired
    private SubjectService subjectService;

    @Override
    public List<Phase> all() {

        return phaseMapper.all();
    }

    @Override
    public Phase findGradesByJid(int jid) {
        //jid
        Phase phase = new Phase().setJid(jid);
        //这里通过调用gradeService中的方法获取年级数据 再赋值给phase对象
        List<Grade> grades = gradeService.findByJid(jid);
        phase.setGrades(grades);
        return phase;
    }

    @Override
    public Phase findByJidAndNid(int jid, int nid) {
        // 阶段
        Phase phase = new Phase().setJid(jid);
        // 年级
        Grade grade = new Grade().setNid(nid);
        // 查询该年级下的所有科目
        grade.setSubjects(subjectService.findSubjectByNid(nid));
        // 转化为list数组
        phase.setGrades(Arrays.asList(grade));

        return phase;
    }


}
